// pages/my/my.js
//阿里图标库  直接单个下载 批量下载png会变颜色
// https://www.iconfont.cn/collections/index?spm=a313x.collections_index.i1.d2b281277.4cc53a81MIFjKl&type=4&page=2
const API = require('../../utils/api.js'); // 引入封装好的 API 方法
const pathUrl = require('../../utils/common.js'); 
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userInfo:{},
    defaultAvatar:'https://thirdwx.qlogo.cn/mmopen/vi_32/POgEwh4mIHO4nibH0KlMECNjjGxQUq24ZEaGT4poC6icRiccVGKSyXwibcPq4BWmiaIGuG1icwxaQX6grC9VemZoJ8rg/132',
    loginFlg:false
  },

   logout(){
    // API.logout();
    wx.removeStorageSync('token');
    this.setData({
      loginFlg:false,
      userInfo:{}
    })
  },

  toLogin() {
    wx.navigateTo({
      url: '/pages/login/login',
    })
  },
  
  // 跳转到用户信息修改页面
  toUserEdit() {
    if(!this.data.loginFlg){
      wx.showToast({
        title: '请先登录',
        icon: 'none',
        duration: 2000
      });
    }else{
      console.log('1231')
      wx.navigateTo({
        url: '/pages/user-edit/user-edit'
      })
    }
  },
  chatai(){
    if(!this.data.loginFlg){
      wx.showToast({
        title: '请先登录', // 提示内容
        icon: 'none',  // 图标类型，可选值：'success', 'loading', 'none'
        duration: 2000,   // 提示框显示时长，单位为毫秒
        mask: true,       // 是否显示透明蒙层，防止触摸穿透
        success: function () {
          console.log('Toast 显示成功');
        },
        fail: function (err) {
          console.error('Toast 显示失败', err);
        }
      });
    }else{
      wx.navigateTo({
        url: '/pages/chatai/chatai'
      })
    }
  },
  
  /**
   * 生命周期函数--监听页面显示
   */
  async onShow() {
    if(wx.getStorageSync('token')){
      let userInfoData = await API.userInfo();
      userInfoData.avatar = pathUrl+userInfoData.avatar
      this.setData({
        loginFlg:true,
        userInfo:userInfoData
      })
      const app = getApp();
      app.globalData.userInfo = userInfoData;
    }
  },
  signManage(){
    wx.navigateTo({
      url: '/pages/sign/manage/manage',
    })
  },
  myTeam(){
    wx.navigateTo({
      url: '/pages/org/list/list',
    })
  },
  gameCenter(){
    wx.navigateTo({
      url: '/pages/games/index/index',
    })
  }
})